/**   
* @Title: HelloController.java
* @Package me.cloud.controller
* @Description: TODO
* @author xaoyaoyao
* @date 2018年11月29日 下午1:50:06
* @version V1.0   
*/
package me.cloud.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import me.cloud.vo.User;

/**
 * @ClassName: HelloController
 * @Description: TODO
 * @author xaoyaoyao
 * @date 2018年11月29日 下午1:50:06
 * 
 */
@RestController
@RequestMapping("/v1/test")
public class HelloController {

	@GetMapping("/")
	public String index() {
		System.out.println("调用 index 方法");
		return "index";
	}

	@GetMapping("/hello")
	public String hello() {
		System.out.println("调用 hello 方法");
		return "hello";
	}

	@GetMapping("/json")
	@ResponseBody
	public Object json() {
		System.out.println("调用 json 方法");
		Map<String, Object> data = new HashMap<>();
		Map<String, Object> map = new HashMap<>();
		map.put("code", 200);
		map.put("msg", "OK");
		data.put("hello", "Welcome to Cloud!");
		map.put("data", data);
		return map;
	}

	@RequestMapping("/param")
	public String parameter(@RequestParam String name) {
		System.out.println("调用 parameter 方法， 参数name：：" + name);
		return name;
	}

	@RequestMapping(value = "/getUser/{name}/{sex}")
	public User getUser(@PathVariable String name, @PathVariable char sex) {
		System.out.println("调用 getUser 方法");
		User user = new User();
		user.setId(12);
		user.setName(name);
		user.setDate(new Date());
		user.setSex(sex);
		return user;
	}

	@RequestMapping(value = "/addUser")
	public User addUser(@RequestBody User user) {
		System.out.println("调用 addUser 方法");
		return user;
	}

}
